﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Security;
using NPMonitor.Web.UserControls;


namespace NPMonitor.Web
{

    public abstract class BasePage : System.Web.UI.Page
    {
        public void FormSingout()
        {
            FormsAuthentication.SignOut();
            Response.Redirect("/account/login.aspx");
        }
       
        public abstract string FunctionName
        {
            get;
        }
        
        public string[] UserInfo
        {
            get
            { 
                return HttpContext.Current.User.Identity.Name.Split('|');
            }
        }

        public string CurrentUser
        {
            get
            {
                if (UserInfo.Length == 2)
                    return UserInfo[1];
                else
                    return string.Empty;
            }
        }

        public int CurrentUserId
        {
            get
            {
                int userId = 0;
                if (int.TryParse(UserInfo[0], out userId))
                    return userId;
                else
                    return 0;
            }
        }

        public void BindDropdownList(DropDownList ddl, IList ds, string text, string value)
        {
            ddl.DataSource = ds;
            ddl.DataTextField = text;
            ddl.DataValueField = value;
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem(CommonString.Select, ""));
        }

        public void NOPageBack()
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }
    }
}